Support older humminbird tracks on read.
authorrobertl <robertl>
Tue, 2 Sep 2008 04:54:05 +0000 (04:54 +0000)
committerrobertl <robertl>
Tue, 2 Sep 2008 04:54:05 +0000 (04:54 +0000)
humminbird.c

index 40273af176b70f7d2e2245baa48391f93efa23af..012f372c64d1c5c4973d21d08ee0046485baea39 100644 (file)
@@ -441,6 +441,9 @@ humminbird_read_track_old(gbfile* fin) {
        gbint32 accum_east;
        gbint32 accum_north;
        double g_lat;
+       const int file_len = 8048;
+       const int name_len = 20;
+       char namebuf[name_len];
 
 
        if (! gbfread(&th, 1, sizeof(th), fin))
@@ -457,7 +460,7 @@ humminbird_read_track_old(gbfile* fin) {
 
        // These files are always 8048 bytes long. Note that that's the value
        // of the second 16-bit word in the signature.
-       max_points = (8048 - sizeof(th)) / sizeof(humminbird_trk_point_old_t);
+       max_points = (file_len - (sizeof(th) + sizeof (gbuint32) + name_len)) / sizeof(humminbird_trk_point_old_t);
 
        if (th.num_points > max_points)
                fatal(MYNAME ": Too many track points! (%d)\n", th.num_points);
@@ -475,7 +478,13 @@ humminbird_read_track_old(gbfile* fin) {
        trk = route_head_alloc();
        track_add_head(trk);
 
-//     trk->rte_name = xstrndup(th.name, sizeof(th.name));
+       /* The name is not in the header, but at the end of the file.
+          (The last 20 bytes.) */
+
+       gbfseek(fin, file_len-name_len, SEEK_SET);
+       gbfread(&namebuf, 1, name_len, fin);
+       trk->rte_name = xstrndup(namebuf, sizeof(namebuf));
+
        trk->rte_num  = th.trk_num;
 
        /* We create one wpt for the info in the header */